﻿using Autofac;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OfficeOpenXml;
using PdfSharpCore.Fonts;
using Quartz;
using System;
using System.ComponentModel;
using System.Xml.Linq;
using Topshelf;
using Topshelf.Autofac;
using Wittur.GenereateKongCoCPDF;
using Wittur.GenereateKongCoCPDF.Core;
using Wittur.GenereateKongCoCPDF.Core.Common;
using Wittur.GenereateKongCoCPDF.Core.Extensions;
using Wittur.GenereateKongCoCPDF.Core.Services;
using static Dapper.SqlMapper;


public class Program
{
    public static void Main(string[] args)
    {
        GlobalFontSettings.FontResolver = new CustomFontResolver();
        // 设置 LicenseContext
        ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
        var builder = new ContainerBuilder()
                             .ConfigureQuartz()
                             .ConfigureAutoMapper()
                             .ConfigureSelf();
        //.ConfigureNlog();
        var container = builder.Build();

        HostFactory.Run(x =>
        {
            x.SetDisplayName(ConfigHelper.Instance.GetString("Service", "DisplayName"));
            x.SetServiceName(ConfigHelper.Instance.GetString("Service", "Name"));
            x.SetDescription(ConfigHelper.Instance.GetString("Service", "Description"));
            x.UseNLog();
            x.UseAutofacContainer(container);

            x.Service<SampleSchedule>(setting =>
            {
                setting.ConstructUsingAutofacContainer();
                setting.ConstructUsing(name => new SampleSchedule(container));
                setting.WhenStarted(async tc => await tc.Start());
                //setting.WhenStarted(tc => tc.Start());
                setting.WhenStopped(tc => tc.Stop());
            });
            x.RunAsLocalSystem();
        });
    }
}